/*------------------------------------------------------------------------------
--                                                                            --
--       This software is confidential and proprietary and may be used        --
--        only as expressly authorized by a licensing agreement from          --
--                                                                            --
--                            Hantro Products Oy.                             --
--                                                                            --
--                   (C) COPYRIGHT 2006 HANTRO PRODUCTS OY                    --
--                            ALL RIGHTS RESERVED                             --
--                                                                            --
--                 The entire notice above must be reproduced                 --
--                  on all copies and should not be removed.                  --
--                                                                            --
--------------------------------------------------------------------------------
--
--  Description : Sytem Wrapper Layer
--
------------------------------------------------------------------------------
--
--  Version control information, please leave untouched.
--
--  $RCSfile: dwl.h,v $
--  $Revision: 1.3 $
--  $Date: 2006/10/02 11:40:53 $
--
------------------------------------------------------------------------------*/
#ifndef __DWL_H__
#define __DWL_H__

#ifdef __cplusplus
extern "C"
{
#endif

#include "basetype.h"
#include "dechw.h"

#define DWL_OK                      0
#define DWL_ERROR                  -1

#define DWL_HW_WAIT_OK              DWL_OK
#define DWL_HW_WAIT_ERROR           DWL_ERROR
#define DWL_HW_WAIT_TIMEOUT         1

#define DWL_CLIENT_TYPE_H264_DEC         1U
#define DWL_CLIENT_TYPE_MPEG4_DEC        2U
#define DWL_CLIENT_TYPE_JPEG_DEC         3U
#define DWL_CLIENT_TYPE_PP               4U
#define DWL_CLIENT_TYPE_VC1_DEC          5U


/* Linear memory area descriptor */
typedef struct DWLLinearMem
{
    u32 *virtualAddress;
    u32 busAddress;
    u32 size;
    u32 *virtAddrfrmAllocPhysMem;
} DWLLinearMem_t;

/* DWLInitParam is used to pass parameters when initializing the DWL */
typedef struct DWLInitParam
{
    u32 clientType;
} DWLInitParam_t;



typedef  struct  DWLHwConfig
{

    u32 maxDecodingWidth ; /* Maximum decoding width supported
                                  by the HW */
    u32 maxPpOutWidth ; /* Maximum output width of Post-Processor */
    u32 h264Enabled ;    /* HW supports h.264 */
    u32 h264HighEnabled ;
    u32 jpegEnabled ;    /* HW supports JPEG */
    u32 mpeg4Enabled ;  /* HW supports MPEG-4 */
    u32 mpeg4AspEnabled ;
    u32 vc1Enabled ;  /* HW supports VC-1 */
    u32 vc1MainEnabled ;
    u32 vc1AdvancedEnabled ;
    u32 ppEnabled ;  /* HW supports Post-Processor */
    u32 ppBlendEnabled ;
   
}DWLHwConfig_t;

    
typedef struct DWLInstance
{
    u32         clientType;         /**< Holds the information about the client type */
    DecHw_t*    pDecHw;             /**< Pointer to the decoder HW instance */
    HANDLE      hInstLock;          // Holds the handle to the system wide mutex                                         
    DWORD       SysIntr;            /**< System-level interrupt id */ 
    HANDLE      hInterruptEvent;    /**< Handle to the interrupt event */
    volatile DWORD * pSysCtrlReg;
} DWLInstance_t;

typedef struct InputInfo
{
    DWORD dwInst;
    DWORD dwClientType;
    DWORD dwSize;
}InputInfo_t;

/* HW ID retriving, static implementation */
u32 DWLReadAsicID(void);

/* DWL initilaization and release */
const void *DWLInit(DWLInitParam_t * param);
i32 DWLRelease(const void *instance);

/* HW sharing */
i32 DWLReserveHw(const void *instance);
void DWLReleaseHw(const void *instance);

/* Frame buffers memory alloc from filters */
u32* DWLMallocBuffer(const void *instance, u32 size, DWLLinearMem_t * info);
void DWLFreeBuffer(const void *instance, DWLLinearMem_t * info);
/* Frame buffers memory */
i32 DWLMallocRefFrm(const void *instance, u32 size, DWLLinearMem_t * info);
void DWLFreeRefFrm(const void *instance, DWLLinearMem_t * info);

/* SW/HW shared memory */
i32 DWLMallocLinear(const void *instance, u32 size, DWLLinearMem_t * info);
void DWLFreeLinear(const void *instance, DWLLinearMem_t * info);

/* D-Cache coherence */
void DWLDCacheRangeFlush(const void *instance, DWLLinearMem_t * info); /* NOT in use */
void DWLDCacheRangeRefresh(const void *instance, DWLLinearMem_t * info); /* NOT in use */

/* Register access */
void DWLWriteReg(const void *instance, u32 offset, u32 value);
u32 DWLReadReg(const void *instance, u32 offset);

void DWLWriteRegAll(const void *instance, const u32 * table, u32 size); /* NOT in use */
void DWLReadRegAll(const void *instance, u32 * table, u32 size); /* NOT in use */

/* HW starting */
void DWLEnableHW(const void *instance); 

/* HW synchronization */
i32 DWLWaitHwReady(const void *instance, u32 timeout);

/* SW/SW shared memory */
void *DWLmalloc(u32 n);
void DWLfree(void *p);
void *DWLcalloc(u32 n, u32 s);
void *DWLmemcpy(void *d, const void *s, u32 n);
void *DWLmemset(void *d, i32 c, u32 n);




#ifdef __cplusplus
}
#endif

#endif /* __DWL_H__ */
